package dao

import (
	"gorm.io/gorm"
	"kf/models/entity"
)

type AboutDao struct {
	DB *gorm.DB
}

func (aboutDao *AboutDao) FindAbouts() []entity.About {
	var a []entity.About
	aboutDao.DB.Select("id,title_cn,page").Find(&a)
	return a
}

func (aboutDao *AboutDao) FindAboutByPage(page interface{}) entity.About {
	var a entity.About
	aboutDao.DB.Where("page = ?", page).First(&a)
	return a
}
func (aboutDao *AboutDao) FindAboutByPageLanguage(page interface{}, lang string) entity.About {
	var a entity.About
	if lang == "" {
		lang = "cn"
	}
	if lang == "en" {
		aboutDao.DB.Select("css_js,title_en,keywords_en,desc_en,html_en").Where("page = ?", page).First(&a)
	} else {
		aboutDao.DB.Select("css_js,title_cn,keywords_cn,desc_cn,html_cn").Where("page = ?", page).First(&a)
	}
	return a
}
func (aboutDao *AboutDao) UpdateAbout(page string, title_cn string, title_en string,
	keywords_cn string, keywords_en string, desc_cn string, desc_en string, css_js string,
	html_cn string, html_en string) {
	c := &entity.About{
		TitleCn:    title_cn,
		TitleEn:    title_en,
		KeywordsCn: keywords_cn,
		KeywordsEn: keywords_en,
		DescCn:     desc_cn,
		DescEn:     desc_en,
		CssJs:      css_js,
		HtmlCn:     html_cn,
		HtmlEn:     html_en,
	}
	aboutDao.DB.Model(c).Where("page = ?", page).Updates(c)
	//InitSysAutoReply()
}
